package com.jzl.swing.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jzl.swing.dao.ReportDao;
import com.jzl.swing.entity.BillReport;
import com.jzl.swing.entity.SupplierReport;
import com.jzl.swing.rowmapper.impl.BillReportRowMapper;
import com.jzl.swing.rowmapper.impl.SupplierReportRowMapper;
import com.jzl.swing.util.JDBCTemplate;

public class ReportDaoImpl implements ReportDao{

	@Override
	public List<BillReport> queryByProduct() {
		List<BillReport> billList = new ArrayList<BillReport>();
		String sql = "select bill_product_name, bill_product_number, bill_price, bill_supplierName from bills";
		List<Object> list = null;
		try {
			list = JDBCTemplate.executeQuery(sql, new BillReportRowMapper());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for (Object object : list) {
			billList.add((BillReport) object);
		}
		return billList;
	}

	@Override
	public List<SupplierReport> queryBySupplier() {
		List<SupplierReport> supplierList = new ArrayList<SupplierReport>();
		String sql = "select s.supplier_id, s.supplier_name, b.bill_price, b.bill_product_number from suppliers s left join bills b on b.bill_supplierName=s.supplier_name;";
		List<Object> list = null;
		try {
			list = JDBCTemplate.executeQuery(sql, new SupplierReportRowMapper());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for (Object object : list) {
			supplierList.add((SupplierReport) object);
		}
		return supplierList;
	}



}
